// nums = [2,7,11,15], target = 9  输出 [0,1]

/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */
var twoSum = function (nums, target) {
  let len = nums.length
  const obj = {}
  for (let i = 0; i < len; i++) {
    if (obj[target - nums[i]] !== undefined) {
      return [obj[target - nums[i]], i]
    }
    obj[nums[i]] = i
  }
};

console.log(twoSum([2, 7, 11, 15], 9));
